package com.duoec.magichour.core.task;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by ycoe on 16/5/14.
 */
public class Tasker {
    private Tasker() {
    }

    /**
     * 线程池
     */
    private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(10);

    /**
     * 有需要数据返回的异步方法
     *
     * @param fector
     * @param <V>
     * @return
     */
    public static <V> Future<V> submit(TaskFector<V> fector) {
        return EXECUTOR_SERVICE.submit(() -> fector.exec());
    }

    /**
     * 不需要数据返回的异步方法
     *
     * @param runner
     */
    public static void execute(TaskRunner runner) {
        EXECUTOR_SERVICE.execute(() -> runner.exec());
    }
}
